package covertjava.protect;

import covertjava.chat.ChatApplication;
import java.io.File;
import covertjava.util.AppProperties;

/**
 * <p>Alternative entry point into the Chat application that applies various
 * protection mechanisms</p>
 * <p>Copyright: Copyright (c) 2004 Sams Publishing</p>
 * @author Alex Kalinovsky
 * @version 1.0
 */
public class ProtectedChatApplication {

    public static void main(String[] args) throws Exception {
        // Verify that the license file is valid
        LicenseManager licenseManager = new LicenseManager("conf/chat.license");

        // Verify that the license manager class is not hacked
        IntegrityProtector protector = new IntegrityProtector();
        protector.assertClassSource(licenseManager.getClass(), "/lib/chat.jar");

        // Read the checksum from configuration file and verify the current installation
        String homePath = System.getProperty("chat.home");
        String propPath = homePath + File.separator + "conf" + File.separator + "chat.properties";
        AppProperties props = new AppProperties(propPath);
        String checkSum = props.getProperty("chat.versionInfo");
        String[] paths = protector.readFilePathsFromResource("ChatFileList.class");
        protector.assertFilesIntegrity(paths, '\\', homePath, checkSum);

        // Check license invormation
        licenseManager.verifySerialNumber("conf/key_public.ser");
        if (licenseManager.isHostAllowed() == false)
            throw new Exception("Host is not allowed by the license");
        if (licenseManager.isLicenseExpired() == true)
            throw new Exception("The license is expired");


        // Launch Chat application
        ChatApplication.main(args);
    }

}
